<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .hide {
        display: none;
    }

    .c1 {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .5);
        z-index: 99;
        margin-top: 0%;
    }

    .c2 {
        background-color: white;
        position: fixed;
        width: 400px;
        height: 300px;
        top: 50%;
        left: 50%;
        z-index: 100;
        margin-top: -150px;
        margin-left: -200px;
        padding-top: 2%;
        padding-left: 2%;
    }

    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_mould_t {
        background-color: #254060;
        height: 443px;
        color: white;
        overflow: hidden;
    }

    .pa_mould_but {
        height: 58px;
        line-height: 58px;
        float: right;
        width: 150px;
        font-size: 30px;
        color: white;
        text-align: center;
        margin-right: 40px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .startBut {
        font-size: 17px;
        color: white;
        font-weight: bold;
        float: right;
        width: 45px;
        margin-right: 10px;
        height: 25px;
        line-height: 25px;
        margin-top: 2.5px;
        text-align: center;
        background-color: green;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟久泰</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:25%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:15%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>模具更换记录查询</p>
            </div>
        </div>
    </div>

    <div class="aui-flex-col aui-flex-center">
        <div class="aui-flex-item-12 pa_mould_t">


            <div class="aui-flex-col" style="height: 35px;margin-top: 5px;">
                <div style="margin-top: 4px;font-size: 15px;color: white;font-weight: bold;width: 70px;">换模日期:
                </div>
                <div onclick="timePicker()"
                    style="background-color: white;width: 100px;height: 30px;margin-left: 5px ;margin-right: 5px ;">
                    <input type="text" style="font-size: 15px;margin-top: -12px;" placeholder="选择日期" id="dateTime"
                        onclick="getIdSelector();">
                </div>

                <div style="margin-top: 4px;font-size: 15px;color: white;font-weight: bold;width: 50px;">班组:
                </div>
                <div style="background-color: white;width: 100px;height: 30px;margin-right: 5px ;">
                    <select type="text" style="font-size: 15px;margin-top: -12px;" placeholder="选择班组" id="groupCode"
                        onclick="getIdSelector();"></select>
                </div>

                <div style="margin-top: 4px;font-size: 15px;color: white;font-weight: bold;width: 50px;">班次:
                </div>
                <div style="background-color: white;width: 200px;height: 30px;margin-right: 5px ;">
                    <select type="text" style="font-size: 15px;margin-top: -12px;" placeholder="选择班次" id="shiftCode"
                        onclick="getIdSelector();"></select>
                </div>


                <div class="startBut" onclick="doSearchMould()">查询</div>

            </div>
            <div class="aui-flex-col" style="height: 400px;overflow: auto;">
                <div class="aui-flex-item-12">
                    <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr style="text-align: center;color: white;font-size: 15px;height: 35px;">
                                <td algin='center' style="width:5%">序号</td>
                                <td algin='center' style="width:10%">班组</td>
                                <td algin='center' style="width:10%">阶段</td>
                                <td algin='center' style="width:10%">模具编码</td>
                                <td algin='center' style="width:10%">模具名称</td>
                                <td algin='center' style="width:20%">开始时间</td>
                                <td algin='center' style="width:20%">结束时间</td>
                                <td algin='center' style="width:10%">时间(min)</td>
                                <!-- <td algin='center' style="width:20%">操作</td> -->
                            </tr>
                        </thead>
                        <tbody id="mouldHtml">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    //光标所在id
    var idSelector = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        console.log(api.pageParam.workCenterName)
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);



        //班组下拉框
        doSearchTeamGid()
        //班次下拉框
        doSearchShiftName()

        //获取当前日期
        crateDate()
        //1：查询换模计划
        doSearchMould();
        api.setFocus({
            inputId: 'rsBarCode',
            focus: true
        });
    }

    //获取当前日期
    function crateDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        $("#dateTime").val(year + "-" + month + "-" + day);
    }

    function doSearchShiftName() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                tablename: "md_paraconfig",
                column_name: "paracode",
                column_value: "paraval",
                condition: "paracls = 'shiftClass'",
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("shiftCode"), html);
            }
        });
    }

    //班组下拉框
    function doSearchTeamGid() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                tablename: "md_labour_group",
                column_name: "group_name",
                column_value: "group_code",
                condition: "is_delete=0 ",
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("groupCode"), html);
            }
        });
    }

    //时间选择器
    function timePicker() {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#dateTime").val(date);
            }
        });
    }

    //响应保存
    function responseSave() {


        var mjCode = document.getElementById('mjCode').value;
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
        document.getElementById('mjCode').value = "";
        console.log(111)
        console.log(mjCode)
        if (mjCode != null && mjCode != "" && mjCode != undefined) {
            $("#rsBarCode").val(mjCode);
            $("#rsBarCode").focus()
            //绑定保存
            bindSave();
        }
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    function toSelectMJ() {
        //选中数据
        var check = $("input[type='checkbox']:checked");
        var count = 0;
        var workOrderCode = "";
        var mrlCode = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            mrlCode = row.find("[name='mrlCode']").html();
            count++;

        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条工单数据!",
                duration: 3000
            });
            return;
        }
        getMjCodeList(mrlCode);
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('modal').classList.remove('hide');


    }

    function Hide() {
        document.getElementById('shade').classList.add('hide');
        document.getElementById('modal').classList.add('hide');
        // document.getElementById('empNo').value = "";
    }

    function getMjCodeList(mrlCode) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMjCodeList";
        var data = {
            values: {
                un: un,
                mrlCode: mrlCode
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == "0") {

                    //生产线
                    var list = eval(myobj.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].value + "</option>";
                    }
                    $api.html($api.byId("mjCode"), html);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }


    //查询换模记录
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyWorkOrder";
        var data = {
            values: {
                proddate: api.pageParam.proddate,
                workCenterCode: api.pageParam.workCenterCode,
                shiftCode: api.pageParam.shiftCode,
                state: "发布,暂停",
                type: "换模计划",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 13px;height:35px;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='workOrderCode'>" + list[i].workOrderCode + "</td>";
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='mrlName'>" + list[i].mrlName + "</td>";
                        html += "<td name='planQty'>" + list[i].planQty + "</td>";
                        html += "<td name='status'>" + list[i].state + "</td>";
                        // html += "<td name='planMouldDate'>" + list[i].planMouldDate + "</td>";
                        // html += "<td name='actualMouldDate'>" + list[i].actualMouldDate + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("workOrderHtml"), html);

                    if (list != null && list.length > 0) {
                        //查询当前模具
                        doSearchMould();
                    } else {
                        $api.html($api.byId("mouldHtml"), "");
                    }
                } else {
                    $api.html($api.byId("workOrderHtml"), "");
                    $api.html($api.byId("mouldHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询当前产线所有模具换模记录
    function doSearchMould() {
        var dateTime = $("#dateTime").val();
        var groupCode = $("#groupCode").val();
        var shiftCode = $("#shiftCode").val();
        if (dateTime == null || dateTime == "" || dateTime == undefined) {
            api.toast({
                msg: "请选择换模日期！",
                duration: 3000
            });
            return false;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyMouldWorkOrderNew";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                un: un,
                dateTime: dateTime,
                groupCode: groupCode,
                shiftCode: shiftCode
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        var endDateIndex = "endDateIndex" + (i + 1);
                        html += "<tr style='text-align: center;color: white;font-size: 13px;height:35px;'>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='groupName'>" + list[i].groupName + "</td>";
                        html += "<td name='stage'>" + list[i].stage + "</td>";
                        if (list[i].ext15 != "4") {
                            html += "<td name='rsCode'>" + (list[i].rsCode ? list[i].rsCode : '') + "</td>";
                            html += "<td name='rsName'>" + (list[i].rsName ? list[i].rsName : '') + "</td>";
                        } else {
                            html += "<td name='rsCode'>" + list[i].rsCode + "</td>";
                            html += "<td name='rsName'>" + list[i].rsName + "</td>";
                        }


                        html += "<td name='startTime'>" + (list[i].startTime ? list[i].startTime : '') + "</td>";
                        html += "<td name='" + endDateIndex + "'>" + list[i].endTime + "</td>";
                        html += "<td name='diffDate'>" + (list[i].diffDate ? list[i].diffDate : '0') + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("mouldHtml"), html);
                } else {
                    $api.html($api.byId("mouldHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //绑定保存
    function bindSave() {
        //机台
        var rsBarCode = $("#rsBarCode").val();
        if (rsBarCode == null || rsBarCode == "" || rsBarCode == undefined) {
            api.toast({
                msg: "请扫描模具条码!",
                duration: 3000
            });
            return false;
        }

        //选中数据
        var check = $("input[type='checkbox']:checked");
        var count = 0;
        var workOrderCode = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            count++;

        });

        if (count != 1) {
            api.toast({
                msg: "请选择一条工单数据!",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyMouldBindSave";
        var data = {
            values: {
                rsBarCode: rsBarCode,
                workOrderCode: workOrderCode,
                workCenterCode: api.pageParam.workCenterCode,
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //刷新表数据
                    refresh();

                } else {
                    $("#rsBarCode").val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    setFocus();
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //解绑
    function unBindSave(rsBarCode) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyMouldUnBindSave";
        var data = {
            values: {
                rsBarCode: rsBarCode,
                workCenterCode: api.pageParam.workCenterCode,
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //刷新表数据
                    refresh();

                } else {
                    $("#rsBarCode").val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    setFocus();
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    function toUnBindMJ() {
        var rsBarCodeEle = document.querySelector("td[name='rsCode']");
        let rsBarCode = rsBarCodeEle ? rsBarCodeEle.textContent : null;
        if (rsBarCode == "" || rsBarCode == null || rsBarCode == undefined) {
            api.toast({
                msg: "未绑定模具,请先绑定模具！",
                duration: 3000
            });
            return;
        }
        api.confirm({
            title: '确认解绑模具',
            msg: "模具条码【" + rsBarCode + "】是否解绑模具？",
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {

                console.log('点击了确定按钮');

                // 进行结束换模操作
                unBindSave(rsBarCode);

            } else {
                console.log('点击了取消按钮');

                $("#rsBarCode").val("");

                api.setFocus({
                    inputId: 'rsBarCode',
                    focus: true
                })
            }
        });
    }

    // 结束换模提示
    function unEndDateTips(rsBarCode, flag, endDate) {
        console.log(11)
        var title = ""
        var msg = ""
        if (flag == '1') {
            title = "确认结束换模"
            msg = "模具条码【" + rsBarCode + "】是否结束换模？"
            if (endDate != "" && endDate != null && endDate != undefined) {
                api.toast({
                    msg: "当前模具已绑定，不要重复操作！",
                    duration: 3000
                });
                return;
            }
        }
        if (flag == "2") {
            title = "确认结束预热"
            msg = "模具条码【" + rsBarCode + "】是否结束预热？"
        }
        if (flag == "3") {
            title = "确认结束调机"
            msg = "模具条码【" + rsBarCode + "】是否结束调机？"
        }

        api.confirm({
            title: title,
            msg: msg,
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {

                console.log('点击了确定按钮');

                // 进行结束换模操作
                unEndDateSave(rsBarCode, flag);

            } else {
                console.log('点击了取消按钮');

                $("#rsBarCode").val("");

                api.setFocus({
                    inputId: 'rsBarCode',
                    focus: true
                })
            }
        });
    }

    // 开始换模提示
    function unEndDateTipsNew(rsBarCode, flag) {
        var title = ""
        var msg = ""
        if (flag == "2") {
            var endDateIndex1Element = document.querySelector("[name='endDateIndex1']");
            let endDateIndex1Value = endDateIndex1Element ? endDateIndex1Element.textContent : null;
            if (endDateIndex1Value == "" || endDateIndex1Value == null || endDateIndex1Value == undefined) {
                api.toast({
                    msg: "当前机台换模未结束，请先结束换模后再进行操作！",
                    duration: 3000
                });
                return;
            }
            title = "确认开始预热"
            msg = "模具条码【" + rsBarCode + "】是否开始预热？"
        }
        if (flag == "3") {
            var endDateIndex1Element = document.querySelector("[name='endDateIndex1']");
            let endDateIndex1Value = endDateIndex1Element ? endDateIndex1Element.textContent : null;
            if (endDateIndex1Value == "" || endDateIndex1Value == null || endDateIndex1Value == undefined) {
                api.toast({
                    msg: "当前机台换模未结束，请先结束换模后再进行操作！",
                    duration: 3000
                });
                return;
            }
            var endDateIndex2Element = document.querySelector("[name='endDateIndex2']");
            let endDateIndex2Value = endDateIndex2Element ? endDateIndex2Element.textContent : null;
            console.log(endDateIndex2Value)
            if (endDateIndex2Value == "" || endDateIndex2Value == null || endDateIndex2Value == undefined) {
                api.toast({
                    msg: "当前机台预热未结束，请先结束预热后再进行操作！",
                    duration: 3000
                });
                return;
            }
            title = "确认开始调机"
            msg = "模具条码【" + rsBarCode + "】是否开始调机？"
        }
        console.log(flag);
        api.confirm({
            title: title,
            msg: msg,
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {

                console.log('点击了确定按钮');

                // 进行结束换模操作
                unEndDateSaveNew(rsBarCode, flag);

            } else {
                console.log('点击了取消按钮');

                $("#rsBarCode").val("");

                api.setFocus({
                    inputId: 'rsBarCode',
                    focus: true
                })
            }
        });
    }

    //结束换模操作
    function unEndDateSave(rsBarCode, flag) {

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyMouldUnEndDate";
        var data = {
            values: {
                rsBarCode: rsBarCode,
                workCenterCode: api.pageParam.workCenterCode,
                un: un,
                flag: flag
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //刷新表数据
                    refresh();

                } else {
                    $("#rsBarCode").val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    setFocus();
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //开始换模操作
    function unEndDateSaveNew(rsBarCode, flag) {

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyMouldUnEndDateNew";
        var data = {
            values: {
                rsBarCode: rsBarCode,
                flag: flag,
                workCenterCode: api.pageParam.workCenterCode,
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //刷新表数据
                    refresh();

                } else {
                    $("#rsBarCode").val("");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    setFocus();
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    function setFocus() {
        api.setFocus({
            inputId: 'rsBarCode',
            focus: true
        });
    }

    //模具条码扫描绑定
    $("#rsBarCode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                $("#rsBarCode").blur();

                //绑定保存
                bindSave();
            }
        }
    });

    //刷新按钮
    function refresh() {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        $("#rsBarCode").val("");
        //查询发布和暂停的工单换模计划信息
        doSearch();

        api.setFocus({
            inputId: 'rsBarCode',
            focus: true
        });
    }

    //取消
    function cancal() {
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'refresh()'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>